
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		Stack<Character> stk = new Stack<>();
		StringBuilder sb = new StringBuilder();

		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String s = sc.nextLine();
			
			for (int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				if (c != ')') {
					stk.add(c);
				} else if (c == ')') {
					sb.delete(0, sb.length());
					while (stk.peek() != '(') {
						sb.append(stk.pop());
					}
					stk.pop();
					String res = calc(sb.reverse().toString());
					sb.delete(0, sb.length());
					for (int j = 0; j < res.length(); j++) {
						stk.add(res.charAt(j));
					}
				}
			}

			while (!stk.isEmpty()) {
				sb.append(stk.pop());
			}
			System.out.println(sb.reverse().toString());

		}
		sc.close();
	}

	private static String calc(String s) {
		StringBuilder sb = new StringBuilder();
		int idx = s.indexOf(" ");
		String oper = s.substring(0, idx);
		String[] a = s.substring(idx + 1).split("\"\\s{1}\"");
		for (int i = 0; i < a.length; i++) {
			a[i] = a[i].replaceAll("\"", "");
		}

		if (oper.equals("combine")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
		} else if (oper.equals("search")) {
			sb.delete(0, sb.length());
			int idx1 = a[0].indexOf(a[1]);
			if (idx1 == -1) {
				sb.append("");
			} else {
				sb.append(a[0].substring(idx1));
			}
		} else if (oper.equals("reverse")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
			String tmp = sb.reverse().toString();
			sb.delete(0, sb.length());
			sb.append(tmp);
		} else if (oper.equals("quote")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
		}
		return "\"" + sb.toString() + "\"";
	}

}
